package UIFree.controls
{
	import UIFree.uif_component;
	
	import flash.geom.Point;
	
	public class uif_baseHint extends uif_label {
		protected var _ori: String = 'bottom';
		
		public function uif_baseHint(parent:uif_component, ax:int=0, ay:int=0, awidth:int=0, aheight:int=0, styleClass:Object='') {
			super(parent, ax, ay, awidth, aheight, styleClass);
		}

		override protected function paint(a_styleClass: String, a_method: String = ''): void {
//			var style: Object = app.styleByName(a_styleClass);
			this.draw_hint(0, 0, width, height, _ori, style);
		}
		
		protected function get arrowSize(): Number {
			return style['arrowSize']?style['arrowSize']:((width>height)?(height/5):(width/5));
		}
		
		protected function draw_hint(x: int, y: int, width: int, height: int, hintTo: String, style: Object): void {
			begin2(style);
			var rounds: Array = [0, 0, 0, 0];
			var hsize: int = arrowSize; 
			if (typeof(style.rounds) == 'number') {
				rounds[0] = style.rounds;
				rounds[1] = style.rounds;
				rounds[2] = style.rounds;
				rounds[3] = style.rounds;
			} else if (typeof(style.rounds) == 'object') rounds = style.rounds;
			
			this.graphics.moveTo(x + rounds[0], y);
			if (hintTo == 'top') {
				this.graphics.lineTo(x + width / 2 - hsize, y);
				this.graphics.lineTo(x + width / 2, y - hsize);
				this.graphics.lineTo(x + width / 2 + hsize, y);
			}
			this.graphics.lineTo(x + width - rounds[1], y);
			this.graphics.curveTo(x + width, y, x + width, y + rounds[1]);
			if (hintTo == 'right') {
				this.graphics.lineTo(x + width, y + height / 2 - hsize);
				this.graphics.lineTo(x + width + hsize, y + height / 2);
				this.graphics.lineTo(x + width, y + height / 2 + hsize);
			}
			this.graphics.lineTo(x + width, y + height - rounds[2]);
			this.graphics.curveTo(x + width, y + height, x + width - rounds[2], y + height);
			if (hintTo == 'bottom') {
				this.graphics.lineTo(x + width / 2 + hsize, y + height);
				this.graphics.lineTo(x + width / 2, y + hsize + height);
				this.graphics.lineTo(x + width / 2 - hsize, y + height);
			}
			this.graphics.lineTo(x + rounds[3], y + height);
			this.graphics.curveTo(x, y + height, x, y + height - rounds[3]);
			if (hintTo == 'left') {
				this.graphics.lineTo(x, y + height / 2 + hsize);
				this.graphics.lineTo(x - hsize, y + height / 2);
				this.graphics.lineTo(x, y + height / 2 - hsize);
			}
			this.graphics.lineTo(x, y + rounds[0]);
			this.graphics.curveTo(x, y, x + rounds[0], y);
			if (style.fill_color) this.graphics.endFill();
		}
		
		public function hintPos(): Point {
			var hsize: int = arrowSize;
			var poss: Object = {
				'top': new Point(width / 2, - hsize - 5),
				'right': new Point(width + hsize + 5, height / 2),
				'bottom': new Point(width / 2, hsize + height + 5),
				'left': new Point(-hsize - 5, height / 2)
			};
			var style: Object = app.styleByName(styleClass);
			return poss[_ori];
		}
	}
}